package com.chat.service.impl;

import com.chat.constant.StatusConstant;
import com.chat.dto.CarpoolOrderDTO;
import com.chat.entity.CarpoolOrder;
import com.chat.mapper.CarpoolOrderMapper;
import com.chat.result.PageResult;
import com.chat.service.CarpoolOrderService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.UUID;

@Service
public class CarpoolOrderServiceImpl implements CarpoolOrderService {

    @Autowired
    private CarpoolOrderMapper carpoolOrderMapper;

    //添加拼车订单
    @Override
    public void addCarpool(CarpoolOrderDTO carpoolOrderDTO) {
        CarpoolOrder carpoolOrder = new CarpoolOrder();
        BeanUtils.copyProperties(carpoolOrderDTO,carpoolOrder);
        carpoolOrder.setOrderId("xyt"+ UUID.randomUUID().toString());
        carpoolOrder.setCreateTime(LocalDateTime.now());
        carpoolOrder.setUpdateTime(LocalDateTime.now());
        carpoolOrder.setStatus(StatusConstant.ENABLE);

        carpoolOrderMapper.addCarpool(carpoolOrder);
    }

    //拼车订单查询
    @Override
    public PageResult getCarpool(Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        Page<CarpoolOrder> carpoolOrders = carpoolOrderMapper.getCarpool();
        return new PageResult(carpoolOrders.getTotal(),carpoolOrders.getResult());
    }
}
